print("-----简易五子棋游戏（控制台版）------")
checkerboard = []
for i in range(10):
    checkerboard.append([])
    for j in range(10):
        checkerboard[i].append('-')
print("--------------------------------")



def msg(flagNum):
    print("---------------------------------")
    print("   1  2  3  4  5  6  7  8  9  10")
    for i in range(len(checkerboard)):
        print(chr(i + ord('A')) + " ", end=' ')
        for j in range(len(checkerboard[i])):
            print(checkerboard[i][j] + ' ', end=' ')
        print()
    print('--------------------------------')
    if (flagNum == 1):
        print('*棋胜利！***')
    else:
        print('o棋胜利！')
    end = input("再来一局?(y/n):")
    if end == 'y':
        checkerboard.clear()
        for i in range(10):
            checkerboard.append([])
            for j in range(10):
                checkerboard[i].append('-')
        print("--------------------------------")
        return True
    else:
        return False


def main():
    finish = True
    flagNum = 1
    flagch = '*'
    x = 0
    y = 0
    while (finish):
        print("   1  2  3  4  5  6  7  8  9  10")
        for i in range(len(checkerboard)):
            print(chr(i + ord('A')) + " ", end=' ')
            for j in range(len(checkerboard[i])):
                print(checkerboard[i][j] + ' ', end=' ')
            print()
        print('--------------------------------')
        if flagNum == 1:
            str = input('请输入棋子坐标（例如A1）:')
        else:
            str = input('请输入棋子坐标（例如J5）:')
            flagNum *= -1
        ch = str[0]
        x = ord(ch) - 65
        y = int(str[1]) - 1
        if (x < 0 or x > 9 or y < 0 or y > 9):
            print('输入棋子坐标有误请重新输入！', end=' ')
            continue
        if (checkerboard[x][y] == '-'):
            if (flagNum == 1):
                checkerboard[x][y] = '*'
            else:
                checkerboard[x][y] = 'o'
        else:
            print('31m*****你输入位置已经有其他棋子，请重新输入！')
            continue
        if (y - 4 >= 0):
            if (checkerboard[x][y - 1] == flagch
                    and checkerboard[x][y - 2] == flagch
                    and checkerboard[x][y - 3] == flagch
                    and checkerboard[x][y - 4] == flagch):
                finish = msg(flagNum)
        if (y + 4 <= 9):
            if (checkerboard[x][y + 1] == flagch
                    and checkerboard[x][y + 2] == flagch
                    and checkerboard[x][y + 3] == flagch
                    and checkerboard[x][y + 4] == flagch):
                finish = msg(flagNum)
        if (x - 4 >= 0):
            if (checkerboard[x - 1][y] == flagch
                    and checkerboard[x - 2][y] == flagch
                    and checkerboard[x - 3][y] == flagch
                    and checkerboard[x - 4][y] == flagch):
                finish = msg(flagNum)
        if (x + 4 >= 9):
            if (checkerboard[x + 1][y] == flagch
                    and checkerboard[x + 2][y] == flagch
                    and checkerboard[x + 3][y] == flagch
                    and checkerboard[x + 4][y] == flagch):
                finish = msg(flagNum)
        if (x - 4 >= 0 and y - 4 >= 0):
            if (checkerboard[x - 1][y - 1] == flagch
                    and checkerboard[x - 2][y - 2] == flagch
                    and checkerboard[x - 3][y - 3] == flagch
                    and checkerboard[x - 4][y - 4] == flagch):
                finish = msg(flagNum)
        if (x + 4 <= 9 and y - 4 >= 0):
            if (checkerboard[x + 1][y - 1] == flagch
                    and checkerboard[x + 2][y - 2] == flagch
                    and checkerboard[x + 3][y - 3] == flagch
                    and checkerboard[x + 4][y - 4] == flagch):
                finish = msg(flagNum)
        if (x - 4 >= 0 and y + 4 <= 9):
            if (checkerboard[x - 1][y + 1] == flagch
                    and checkerboard[x - 2][y + 2] == flagch
                    and checkerboard[x - 3][y + 3] == flagch
                    and checkerboard[x - 4][y + 4] == flagch):
                finish = msg(flagNum)
        if (x + 4 <= 9 and y + 4 <= 9):
            if (checkerboard[x + 1][y + 1] == flagch
                    and checkerboard[x + 2][y + 2] == flagch
                    and checkerboard[x + 3][y + 3] == flagch
                    and checkerboard[x + 4][y + 4] == flagch):
                finish = msg(flagNum)
        if flagNum == 1:
            flagNum = 0
        else:
            flagNum = 1


main()
